package com.qf.service.impl;


import com.qf.Resp.BaseResp;
import com.qf.assetsappraisal.Assetsappraisal;
import com.qf.dao.AssetsappraisalDao;
import com.qf.service.AssetsappraisalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssetsappraisalServiceImpl implements AssetsappraisalService {
    @Autowired
    AssetsappraisalDao assetsappraisalDao;



    //声明返回BaseResp
    BaseResp baseResp = new BaseResp();

    @Override
    //查所有
    public List<Assetsappraisal> findAllAssetsappraisal() {
        return assetsappraisalDao.findAll();
    }
    //由申请表id 和证模糊查
    @Override
    public List<Assetsappraisal> findByBorrowerIdOrCertificateNameContaining(Integer borrowerId, String certificateName) {
        System.out.println("1232432543543 ");
        return assetsappraisalDao.findByBorrowerIdOrCertificateNameContaining(borrowerId,certificateName);
    }

  /*  @Override

    public BaseResp findByBorrowerId(Integer borrowerId) {

        Assetsappraisal byBorrowerId = assetsappraisalDao.findByBorrowerId(borrowerId);

        if (borrowerId==byBorrowerId.getBorrowerId()){
            baseResp.setCode(200l);
            baseResp.setMessage(byBorrowerId);
            return baseResp;
        }else{
            baseResp.setCode(100001l);
            baseResp.setMessage("这个申请id不存在");
        }






        return null;
    }*/

    //以申请id查多个
    @Override
    public List<Assetsappraisal> findAllByBorrowerId(Integer borrowerId) {

        return assetsappraisalDao.findAllByBorrowerId(borrowerId);
    }

    @Override
    //由资产评估id查
    public Assetsappraisal findById(Integer id) {
        //    return new Assetsappraisal();//待修改
        return assetsappraisalDao.findById(id).get();
    }
    //增改
    @Override
    public String saveOrUpdate(Assetsappraisal assetsappraisal) {
        Assetsappraisal assetsappraisal1 = assetsappraisalDao.saveAndFlush(assetsappraisal);
        if (assetsappraisal1!=null){
            return "success";
        }else {
            return "fail";
        }
    }
    //删
    @Override
    public String deleteById(Integer id) {
        assetsappraisalDao.deleteById(id);
//        System.out.println("输出为：" +assetsappraisalDao.deleteById(id));
        if (id != null) {
            return "success";
        } else {
            return "id不存在";
        }

    }


    //@Override
    //public Assetsappraisal saveOrUpdateByBorrowerId(Integer borrowerId) {
    //
    //
    //    Assetsappraisal assetsappraisal = assetsappraisalRepository.saveOrUpdateByBorrowerId(borrowerId);
    //    Integer id = assetsappraisal.getId();
    //    if (id != null) {
    //        Assetsappraisal assetsappraisal1 = assetsappraisalRepository.saveAndFlush(assetsappraisal);
    //    }
    //
    //    return assetsappraisal;
    //
    //}


}
